<%= link_to(show_file_path(path), class: "open_dir") do %>
  <div class="hitarea collapsable-hitarea"></div>
<% end %>
<span class="folder">
  <%= link_to(File.basename(path), action: :show, path: path) %>
</span>
<ul>
  <% files = Dir.glob(File.join(path, "*")).sort{|a,b|[(File.directory?(a) ? 0 : 1), File.basename(a)] <=> [(File.directory?(b) ? 0 : 1), File.basename(b)]} %>
  <% files.each.with_index(1) do |file, index| %>
    <% show_file_path = show_file_path(file) %>
    <% if File.directory?(file) %>
      <li class="closed expandable <%= "last" if files.size == index%>">
        <%= link_to(show_file_path, class: "closed_dir") do %>
          <div class="hitarea closed-hitarea expandable-hitarea"></div>
        <% end %>
        <span class="folder">
          <%= link_to(File.basename(show_file_path), action: :show, path: show_file_path) %>
        </span>
      </li>
    <% else %>
      <li class="<%= "last" if files.size == index%>"><span class="file"><%= link_to(File.basename(show_file_path), action: :show, path: show_file_path) %></span></li>
    <% end %>
  <% end %>
</ul>